package com.example.demo.reducer;
import java.io.IOException;

import com.example.demo.bean.FlowBean;
import com.example.demo.bean.PhoneBean;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MyReducer extends Reducer<PhoneBean, FlowBean, PhoneBean, FlowBean>{
        @Override
        protected void reduce(PhoneBean k2, Iterable<FlowBean> v2s,
                              Reducer<PhoneBean, FlowBean, PhoneBean, FlowBean>.Context context) throws IOException, InterruptedException {
            long upFlow = 0L, downFlow = 0L;
            for (FlowBean v2 : v2s) {
                upFlow += v2.getUpFlow();
                downFlow += v2.getDownFlow();
            }
            context.write(k2, new FlowBean(upFlow, downFlow));
        }
}